package request

import (
	"github.com/astaxie/beego/validation"
	"shop-common/utils"
)

type AreaRequest struct {
	AreaId   uint   `json:"areaId"`                      //主键
	AreaName string `json:"areaName" binding:"required"` //地区名称 必填
	ParentId uint   `json:"parentId"`                    //上级地区
	Level    int    `json:"level" binding:"required"`    //地区层级 必填
}

func (a *AreaRequest) Valid(v *validation.Validation) {
	if a.AreaName == "" {
		v.SetError("AreaName", "地区名称不能为空")
	} else if !utils.IntIncludes([]int{1, 2, 3}, a.Level) {
		v.SetError("Level", "地区层级不能为空")
	}
}
